﻿namespace Probel.Statistics.Helpers
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;

    internal static class WindowsVersionConverter
    {
        #region Fields

        private const string EIGHT = "Windows 8";
        private const string EIGHT_DOT_ONE = "Windows 8.1";
        private const string SEVEN = "Windows 7";
        private const string VISTA = "Windows Vista";

        #endregion Constructors

        #region Methods

        public static string ToCommercialVersion(this string versionStr)
        {
            
            versionStr = versionStr.Replace("Microsoft Windows NT", string.Empty);
            versionStr = versionStr.Replace("Service Pack 1", string.Empty);

            var version = new Version(versionStr);

            if (version.Major == 6)
            {
                if (version.Minor == 0) { return VISTA; }
                else if (version.Minor == 1) { return SEVEN; }
                else if (version.Minor == 2) { return EIGHT; }
                else if (version.Minor == 3) { return EIGHT_DOT_ONE; }
                else { version.ToString(); }
            }

            return version.ToString();
        }

        #endregion Methods
    }
}